<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/11/3
 * Time: 9:50
 */

namespace app\Service;


class SignatureService
{
    protected $secret_id;
    protected $secret_key;

    public function __construct()
    {

        $this->secret_id = config('app.secret_id');
        $this->secret_key = config('app.secret_key');
    }

    public function signature()
    {
        $current = time();
        $expired = $current + 86400;  // 签名有效期：1天

// 向参数列表填入参数
        $arg_list = array(
            "secretId" => $this->secret_id,
            "currentTimeStamp" => $current,
            "expireTime" => $expired,
            "random" => rand());

// 计算签名
        $original = http_build_query($arg_list);
        $signature = base64_encode(hash_hmac('SHA1', $original, $this->secret_key, true) . $original);

        return $signature;
    }
}